package quickcore.push;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import java.util.Iterator;
import java.util.Set;

public abstract class BasePushAdapter implements Adapter{
    private Context context;
    private static final int WHAT_SET_ALIAS = 0X01;
    private Handler handler = new Handler(Looper.getMainLooper()){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case WHAT_SET_ALIAS:
                    PushBean pb = (PushBean) msg.obj;
                    pb.getPushWrap().setAlias(pb.getAlias());
                    break;
            }
        }
    };
    public BasePushAdapter(Context context){
        this.context = context;
    }
    protected Context getContext(){
        return context;
    }

    @Override
    public void setAlias(String alias) {
        for(Iterator<PushWrap> iterator = getPushServices().iterator();iterator.hasNext();){
            PushBean pb = new PushBean(iterator.next(),alias);
            Message message = new Message();
            message.what = WHAT_SET_ALIAS;
            message.obj = pb;
            handler.sendMessage(message);
        }
    }

    @Override
    public void init() {
        for(Iterator<PushWrap> iterator = getPushServices().iterator();iterator.hasNext();){
            iterator.next().init();
        }
    }
}
